#ifndef PROCESSOR_
#define PROCESSOR_

#include "typedef.hpp"
#include <cstdint>
#include <string>

// IRegs label
constexpr uint8_t Return = 11;
constexpr uint8_t ADDRX = 12;
constexpr uint8_t Base = 13;
constexpr uint8_t Stack = 14;

// SRegs label
#define Code 0
#define ExcCode 0
#define Cause 1
#define Status 2
#define IE 3
#define IP 4
#define IDTR 5
#define EDTR 6
#define PDTR 7

// IMMs label
#define MAR 0
#define MDR 1
#define IX 2
#define IY 3

template <typename T>
class Reg
{
private:
	pair<T *, T *> *data;
	int size;

public:
	Reg();
	Reg(int, std::string);
	~Reg();
	T &operator[](int); // 取引用，访问数值
	T *operator()(int); // 取指针，访问地址
};

class Control // 硬布线式控制器
{
private:
	union Command
	{
		uint64_t data;
		struct OPs
		{
			uint8_t opType;
			uint8_t opVal;
			uint8_t rd;
			uint8_t rs1;
			uint8_t op2;
			uint8_t rs2;
			uint16_t imm;
		} list;
	} IR;

public:
	Control() = default;
	~Control() = default;

	// 分类型的取指流程
	void idI() const;

	// 指令流水线
	inline void fetch();
	void decode();
	inline void execute() const;
	inline void memory() const;
	inline void post();
	void mainLoop();
};

#endif